home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / QuickTime Sample Code / Mixed Bag / AlwaysPreview / AlwaysPreview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-04  |  5.2 KB  |  205 lines  |  [TEXT/KAHL]

  1. /*
  2. This simple app demonstrates how to force the preview enabled mode by install a modal
  3. dialog filter proc in the CustomGetFilePreview routine. This works with System 7 call.
  4. You should check out the Standard File documentation in Inside Mac: Files as well.
  5.  
  6. This sample is based on CustomPreview code in QT1.0 CD.
  7.  
  8. Larry Lai
  9. Developer Technical Support
  10. Apple Computer, Inc.
  11.  
  12. Feburary 3, 1995
  13.  
  14. */
  15.  
  16. #include "ImageCompression.h"
  17. #include <Files.h>
  18. #include <GestaltEqu.h>
  19. #include <StandardFile.h>
  20. #include <Controls.h>
  21.  
  22. // some constants for the buttons we added to the dialog
  23. enum {
  24.     buttonPictureFiles = 16,
  25.     buttonAllFiles
  26. };
  27.  
  28. // prototypes
  29. void updateFileButtons(DialogPtr d, Boolean showAllFiles);
  30. pascal short myDialogHook7(short item, DialogPtr d, Boolean *showAllFiles);
  31. pascal Boolean myFileFilter7(CInfoPBPtr pb, Boolean *showAllFiles);
  32. Boolean doCustom7(FSSpec *fss);
  33. pascal    Boolean    myModalFilter7(DialogPtr theDlg, EventRecord *theEvent, short *itemHit, Boolean *showAllFiles);
  34.  
  35.  
  36. /*
  37.     resource id numbers of the dialogs.
  38.  
  39.     Note that both of these dialogs have a Dialog Color Table ('dctb')
  40.     resource as well. This is so that the window used by Standard File will
  41.     be a color window. In some cases this may allow previews to display more
  42.     accurate colors. On System 7, owing to a bug in the PopUp menu CDEF, it
  43.     is necessary to make it a color window, or else the CDEF draws incorrectly
  44.     in some cases (when the port origin is not (0,0)).
  45. */
  46. #define Custom7DialogID (129)
  47.  
  48. // a global to keep track of whether we are showing all files or just pictures
  49. Boolean gShowAllFiles = false;
  50.  
  51. Boolean doCustom7(FSSpec *fss);            // returns true if a file was selected
  52.  
  53. /*
  54.      routine shared by both the system 6 and system 7 filters. 
  55.      this routine simply hilites the two radio buttons depending on
  56.          the value of the "showAllFiles" parameter.
  57. */
  58. void updateFileButtons(DialogPtr d, Boolean showAllFiles)
  59. {
  60.     short kind;
  61.     Rect r;
  62.     ControlHandle ch;
  63.  
  64.     GetDItem(d, buttonPictureFiles, &kind, (Handle *)&ch, &r);
  65.     SetCtlValue(ch, !showAllFiles);
  66.  
  67.     GetDItem(d, buttonAllFiles, &kind, (Handle *)&ch, &r);
  68.     SetCtlValue(ch, showAllFiles);
  69. }
  70.  
  71.  
  72. /*****************************************************
  73.  
  74.     System 7 Preview code
  75.  
  76.     Note that the system 7 standard file interface allows for a
  77.         YDPtr (YourDataPtr) to be passed to all filters. This means
  78.         that the filter procs do not need to use any global
  79.         variables.
  80.  
  81. ******************************************************/
  82.  
  83. pascal short myDialogHook7(short item, DialogPtr d, Boolean *showAllFiles)
  84. {
  85.  
  86.     switch (item) {
  87.         case sfHookFirstCall:
  88.                 // put buttons in correct initial state
  89.                 updateFileButtons(d, *showAllFiles);
  90.                 break;
  91.         case buttonPictureFiles:
  92.                 if (*showAllFiles) {
  93.                     *showAllFiles = false;
  94.                     updateFileButtons(d, *showAllFiles);
  95.                     item = sfHookRebuildList;    // force standard file to redisplay list
  96.                 }
  97.                 break;
  98.         case buttonAllFiles:
  99.                 if (!*showAllFiles) {
  100.                     *showAllFiles = true;
  101.                     updateFileButtons(d, *showAllFiles);
  102.                     item = sfHookRebuildList;    // force standard file to redisplay list
  103.                 }
  104.                 break;
  105.     }
  106.  
  107.     return(item);
  108. }
  109.  
  110. pascal Boolean myFileFilter7(CInfoPBPtr pb, Boolean *showAllFiles)
  111. {
  112.     /*
  113.         return false to indicate that file/directory should be displayed.
  114.         note that unlike the system 6 version of this filter, you can suppress the
  115.         display of directories as well as files. thus the extra check for directories
  116.         is required below
  117.     */
  118.  
  119.     if (*showAllFiles)
  120.         return(false);
  121.     else {
  122.         if (pb->hFileInfo.ioFlFndrInfo.fdType == 'PICT')
  123.             return(false);
  124.         else
  125.             return(!(pb->hFileInfo.ioFlAttrib & 16));        // directory
  126.     }
  127. }
  128.  
  129. pascal    Boolean    myModalFilter7(DialogPtr theDlg, EventRecord *theEvent, short *itemHit, Boolean *showAllFiles)
  130. {
  131.     short    iType;
  132.     Handle    iHandle;
  133.     Rect    iRect;
  134.     short    c;
  135.     
  136.     *showAllFiles = true;
  137.     
  138.     /*
  139.         handle null event, set the control value of show preview checkbox to 1 if it is 
  140.         unchecked. event from ModalDialog will pass here first before it gets handed to
  141.         the standard file package filter
  142.         
  143.     */
  144.  
  145.     switch (theEvent->what) {
  146.         case nullEvent:
  147.             *itemHit = 15;  // 15 is the resource ID of show preview checkbox
  148.             GetDItem(theDlg, *itemHit, &iType, &iHandle, &iRect);
  149.             c = GetCtlValue ((ControlHandle) iHandle);
  150.     
  151.             if (!c){
  152.                 SetCtlValue((ControlHandle)iHandle, true);
  153.             }
  154.             else
  155.                 return false;
  156.                 
  157.             return true;
  158.             break;
  159.         default:
  160.             return false;
  161.     }
  162. }
  163.         
  164. Boolean doCustom7(FSSpec *fss)
  165. {
  166.     Point where;
  167.     StandardFileReply reply;
  168.  
  169.     where.h = where.v = -2;                // center the dialog on the "best" screen
  170.  
  171.     CustomGetFilePreview((FileFilterYDProcPtr)myFileFilter7, -1, 0, &reply, Custom7DialogID, where,
  172.                             (DlgHookYDProcPtr)myDialogHook7, (ModalFilterYDProcPtr)myModalFilter7, 0, 0, &gShowAllFiles);
  173.  
  174.     return(reply.sfGood);
  175. }
  176.  
  177. /*
  178.     Simple main routine.
  179.  
  180. */
  181. void main(void)
  182. {
  183.     long response;
  184.     FSSpec fileSpec;
  185.  
  186.     // initialize the world
  187.     InitGraf(&thePort);
  188.     InitFonts();
  189.     InitWindows();
  190.     InitMenus();
  191.     TEInit();
  192.     InitDialogs(0L);
  193.     InitCursor();
  194.     MaxApplZone();
  195.  
  196.     // must have image compression manager to use Standard Preview
  197.     if (Gestalt(gestaltCompressionMgr, &response))
  198.         return;
  199.  
  200.     // system 7 calls are only available if the standard file selectors 5 through 8 are around
  201.     if ( (Gestalt(gestaltStandardFileAttr, &response) == noErr) &&
  202.         BitTst((Ptr)&response, 31 - gestaltStandardFile58) )
  203.         doCustom7(&fileSpec);
  204. }
  205.